package com.hengxinguotong.hxgtwygsp.ui.regulation.policy;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Rule;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseTabFragment;
import com.hengxinguotong.hxgtwygsp.ui.readFile.FileDisplayActivity;
import com.hengxinguotong.hxgtwygsp.ui.regulation.NoticeAndRuleData;
import com.hengxinguotong.hxgtwygsp.ui.regulation.RuleAdapter;
import com.hengxinguotong.hxgtwygsp.utils.CommUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * 公示公告
 */
public class PolicyFragment extends BaseTabFragment
{
    @BindView(R.id.policy_recycler)
    RecyclerView policyRecycler;

    private RuleAdapter mAdapter;
    private List<Rule> mList = new ArrayList<>();

    public PolicyFragment()
    {
    }

    @Override
    public int getLayoutResId()
    {
        return R.layout.fragment_policy;
    }

    @Override
    public void init()
    {
        mList = NoticeAndRuleData.getPublicAllList();

        mAdapter = new RuleAdapter(R.layout.item_rule,mList);
        LinearLayoutManager manager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        policyRecycler.setLayoutManager(manager);
        policyRecycler.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Rule rule = mList.get(position);
                FileDisplayActivity.show(getContext(), rule.getTitle(), CommUtil.getDataDir(getContext()) + File.separator +rule.getFileName());
            }
        });
    }

}
